/*
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Library General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
*/

#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QDir>

#include "mainwindowimpl.h"
//
int main(int argc, char ** argv)
{
    QApplication app( argc, argv );

#ifdef Q_WS_WIN
    // To read/write the configuration file and the style file near the main file.
    QDir::setCurrent(QApplication::applicationDirPath());
#endif

    bool useTranslation = true;
	QString locale = "";

    // Process command line
    if (argc > 1)
    {
        for (int i = 1; i < argc; i++)
        {
            if (QString(argv[i]) == "-notranslation")
                useTranslation = false;
            else
                useTranslation = true;

			if (QString(argv[i]).startsWith("-translation"))
			{
				locale = QString(argv[i]).remove(0, QString("-translation").length() + 1);
			}
        }
    }
	
	if (useTranslation)
	{
		if (locale == "")
			locale = QLocale::system().name();
	}
	else
		locale = "";

	QTranslator translatorQt;
	translatorQt.load(QString(":/translations/qt_") + locale);
	QTranslator translatorApp;
	translatorApp.load(QString(":/translations/nagaina_") + locale);
	app.installTranslator(&translatorQt);
	app.installTranslator(&translatorApp);

    MainWindowImpl win;
    win.show();

    app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
    return app.exec();
}
